package com.xinsilu.hospital.controller;


import com.xinsilu.common.Result;
import com.xinsilu.hospital.entity.DrugTable;
import com.xinsilu.hospital.service.IDrugTableService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author ym
 * @since 2021-09-22
 */
@RestController
@CrossOrigin   //解决跨域
@RequestMapping("/api/hospital/drugTable")
public class DrugTableController {
    @Autowired
    private IDrugTableService iDrugTableService;

    @RequestMapping("/getList")
    public Object getList() {
        List<DrugTable> list = iDrugTableService.list(null);
        return Result.ok(list);
    }
    @RequestMapping("/getListDrug")
        public Object getListDrug(DrugTable drugTable){
        List<DrugTable> drug = iDrugTableService.listDrug(drugTable);
        System.out.println(drug);

        return  Result.ok(drug);

    }



    @RequestMapping("/add")
    public Object add(DrugTable drugTable) {
        boolean count = iDrugTableService.save(drugTable);
        if (count) {
            return Result.ok("新增成功");
        }
        return Result.ok("异常");

    }

    @RequestMapping("/getId")
    public Object getId(int id) {
        DrugTable byId = iDrugTableService.getById(id);
        return Result.ok(byId);
    }

    @RequestMapping("/update")
    public Object update(DrugTable drugTable) {
        boolean b = iDrugTableService.updateById(drugTable);
        if (b) {
            return Result.ok("修改成功");
        }
        return Result.ok("修改失败");
    }
    @RequestMapping("/delect")
    public Object delect(int id) {
        boolean b = iDrugTableService.removeById(id);
        if (b) {
            return Result.ok("删除成功");
        }
        return Result.ok("删除失败");
    }

    @RequestMapping("/xiugaishu")
    public Object xiugaishu(DrugTable drugTable) {
        boolean b = iDrugTableService.xiugaishu(drugTable);
        if (b) {
            return Result.ok("成功");
        }
        return Result.ok("失败");
    }
}
